<?php
/**
 * Helps for other extensions.
 *
 * @package Extensions
 * @version @@VERSION@@
 * @subpackage Low-Cal_Vanilla
 * @copyright Damien Lebrun 2007
 * @author Damien Lebrun
 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GPLv2
 */


/**
 * Add a script to the list script to pack.
 *
 * @example ../ReadMe.txt 53 73:
 * @return bool
 * @param Context $Context
 * @param Head $Head
 * @param string $Script Script to add (Must be relative to the vanilla folder).
 * @param int $Index position of the script in the list of script.
 */
function LowCalVanilla_AddScript(&$Context, &$Head, $Script, $Index = 300) {
	if (!isset($Context->Configuration['LOWCALVANILLA_PACKER_ENABLE'])
		|| !$Context->Configuration['LOWCALVANILLA_PACKER_ENABLE']
	) {
		$Head->AddScript($Script);
		return false;
	}

	if (!isset($Context->PassThruVars['LOWCALVANILLA_SCRIPTS'])
		|| !is_array($Context->PassThruVars['LOWCALVANILLA_SCRIPTS'])
	) {
		$Context->PassThruVars['LOWCALVANILLA_SCRIPTS'] = array();
		$Context->PassThruVars['LOWCALVANILLA_SCRIPTS_CLEANUP_POSITION'] = count($Head->Scripts);
	}

	if (!in_array($Script, $Context->PassThruVars['LOWCALVANILLA_SCRIPTS'])) {

		while (isset($Context->PassThruVars['LOWCALVANILLA_SCRIPTS'][$Index])) {
			$Index++;
		}
		$Context->PassThruVars['LOWCALVANILLA_SCRIPTS'][$Index] = $Script;
	}
	return true;
}

if (!defined('LOWCALVANILLA_DIR')) {
	require_once('Control.CleanUp.php');

	$LowCalVanilla_CleanUp = new LowCalVanilla_CompressPage($Context);
	$Page->$Page->AddRenderControl($LowCalVanilla, 0);
}